package panel.help
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	
	import assists.HtmlText;
	import assists.Lang;
	import assists.SizeManager;
	import assists.TextFieldUtils;
	import assists.URI;
	import assists.resource.ResourceLoader;
	
	import inerface.ITraffic;
	
	import panel.publicPanel.NavigationBar;
	import panel.viewSpots.StaticSlide;
	
	public class TrafficPanel extends Sprite implements ITraffic
	{
		private var _stage:Stage;
		private var _loader:ResourceLoader;
		private var _lang:Lang;
		private var _uri:URI;
		
		private var _container:Sprite = new Sprite();
		private var _seaTraffic:Sprite = new Sprite();
		private var _shortContainer:Sprite = new Sprite();
		private var _data:Object;
		public function TrafficPanel()
		{
			super();
		}
		
		public function init(stage:Stage, loader:ResourceLoader, lang:Lang, uri:URI=null):void
		{
			_stage = stage;
			_loader = loader;
			_lang = lang;
			_uri = uri;
			
			
			var guideBtns:NavigationBar = new NavigationBar(_loader,_stage);
			guideBtns.show([{label:"长途汽车",func:showLongTraffic},{label:"市内汽车",func:showShortTraffic},{label:"航班",func:showSeaTraffic}]);
			guideBtns.y = SizeManager.guideUpHeight;
			_container.y = guideBtns.y +　guideBtns.height * 1.1;
			_seaTraffic.y = _container.y;
			_seaTraffic.visible = false;
			_shortContainer.y = _container.y;
			_shortContainer.visible = false;
			this.addChild(_container);
			this.addChild(_shortContainer);
			this.addChild(_seaTraffic);
			this.addChild(guideBtns);
		}
		
		public function show(dataList:Object):void
		{
			_data = dataList;
			var trafficItem:TrafficItem = new TrafficItem(_stage);
			trafficItem.fontSize = 24;
			trafficItem.show({start:"起始",end:"到达",time:"时间"});
			_container.addChild(trafficItem);
			
			_container.graphics.lineStyle(1);
			_container.graphics.moveTo(20,trafficItem.height * 1.2);
			_container.graphics.lineTo(_stage.stageWidth - 20,trafficItem.height * 1.2);
			
			for(var i:int=0;i<dataList.longList.length;i++)
			{
				var item:TrafficItem = new TrafficItem(_stage);
				item.show(dataList.longList[i]);
				item.y = trafficItem.height * 1.4 + i * 1.2 * item.height;
				_container.addChild(item);
			}
			drawRect();
			var tipTxt:TextField = new TextField();
			tipTxt.mouseEnabled = false;
			tipTxt.width = _stage.stageWidth * 0.9;
			tipTxt.wordWrap = true;
			tipTxt.multiline = true;
			TextFieldUtils.setHtmlText(tipTxt,HtmlText.format(_data.longTip,0xffffff));
			tipTxt.y = _container.height;
			tipTxt.x = _stage.stageWidth * 0.05;
		   _container.addChild(tipTxt);
			
			
			StaticSlide.beginSlide(_container,_stage,new Rectangle(0,_container.y,0,-_container.height + _container.y + SizeManager.guideDownHeight),_container.y);
		}
		
		private function drawRect():void
		{
			var startPosX:int = 20;
			var startPoxY:int = 0;
			var endPosX:int = _stage.stageWidth - 20;
			
			_container.graphics.lineStyle(1);
			_container.graphics.moveTo(startPosX,startPoxY);
			_container.graphics.lineTo(startPosX,_container.height);
			_container.graphics.lineTo(endPosX,_container.height);
			_container.graphics.lineTo(endPosX,startPoxY);
			_container.graphics.lineTo(startPosX,startPoxY);
			
			_container.graphics.moveTo(_stage.stageWidth / 3,startPoxY);
			_container.graphics.lineTo(_stage.stageWidth / 3,_container.height);
			
			_container.graphics.moveTo(_stage.stageWidth / 3 * 2,startPoxY);
			_container.graphics.lineTo(_stage.stageWidth / 3 * 2,_container.height);
		}
		
		private function showLongTraffic():void
		{
			_seaTraffic.visible = false;
			_shortContainer.visible = false;
			_container.visible = true;
			StaticSlide.beginSlide(_container,_stage,new Rectangle(0,_container.y,0,-_container.height + SizeManager.guideHeight),_container.y);
		}
		
		private function showShortTraffic():void
		{
			_seaTraffic.visible = false;
			_shortContainer.visible = true;
			_container.visible = false;
			
			if(_shortContainer.numChildren == 0)
			{
			var topSpr:Sprite = new Sprite();
				var nameTxt:TextField = new TextField();
				var startTxt:TextField = new TextField();
				var timeTxt:TextField = new TextField();
				nameTxt.mouseEnabled = false;
				startTxt.mouseEnabled = false;
				timeTxt.mouseEnabled = false;
				nameTxt.autoSize = "left";
				startTxt.autoSize = "left";
				timeTxt.autoSize = "left";
				TextFieldUtils.setHtmlText(nameTxt,HtmlText.format("线路",0xffffff,22));
				TextFieldUtils.setHtmlText(startTxt,HtmlText.format("起站",0xffffff,22));
				TextFieldUtils.setHtmlText(timeTxt,HtmlText.format("发车时间",0xffffff,22));
				
				var startX:int = _stage.stageWidth * 0.02;
				var endX:int = _stage.stageWidth * 0.98;
				topSpr.graphics.lineStyle(1);
				topSpr.graphics.moveTo(startX,0);
				topSpr.graphics.lineTo(startX,nameTxt.height * 1.2);
				topSpr.graphics.lineTo(endX,nameTxt.height * 1.2);
				topSpr.graphics.lineTo(endX,0);
				topSpr.graphics.lineTo(startX,0);
				
				topSpr.graphics.moveTo(startX + _stage.stageWidth * 0.3,0);
				topSpr.graphics.lineTo(startX + _stage.stageWidth * 0.3,nameTxt.height * 1.2);
				
				topSpr.graphics.moveTo(startX + _stage.stageWidth * 0.5,0);
				topSpr.graphics.lineTo(startX + _stage.stageWidth * 0.5,nameTxt.height * 1.2);
				topSpr.graphics.endFill();
				
				nameTxt.x = (_stage.stageWidth * 0.3 - nameTxt.width) * 0.5;
				startTxt.x = startX + _stage.stageWidth * 0.3 + (_stage.stageWidth * 0.2 - startTxt.width) * 0.5;
				timeTxt.x = startX + _stage.stageWidth * 0.5 + (_stage.stageWidth * 0.48 - timeTxt.width) * 0.5;
				
				topSpr.addChild(nameTxt);
				topSpr.addChild(startTxt);
				topSpr.addChild(timeTxt);
				_shortContainer.addChild(topSpr);
				for(var i:int=0;i<_data.shortList.length;i++)
				{
					var item:TrafficCarItem = new TrafficCarItem(_stage);
					item.show(_data.shortList[i]);
					item.y = item.height * i + topSpr.height;
					_shortContainer.addChild(item);
				}
				
				var tipTxt:TextField = new TextField();
				tipTxt.mouseEnabled = false;
				tipTxt.width = _stage.stageWidth * 0.9;
				tipTxt.wordWrap = true;
				tipTxt.multiline = true;
				TextFieldUtils.setHtmlText(tipTxt,HtmlText.format(_data.shortTip,0xffffff));
				tipTxt.y = _shortContainer.height;
				tipTxt.x = _stage.stageWidth * 0.05;
				_shortContainer.addChild(tipTxt);
				
			}
				StaticSlide.beginSlide(_shortContainer,_stage,new Rectangle(0,_shortContainer.y,0,-_shortContainer.height + SizeManager.guideHeight),_shortContainer.y);
			
			
		}
		
		private function showSeaTraffic():void
		{
			_seaTraffic.visible = true;
			_shortContainer.visible = false;
			_container.visible = false;
			if(_seaTraffic.numChildren == 0)
			{
				var seaTxt:TextField = new TextField();
				seaTxt.mouseEnabled = false;
				seaTxt.width = _stage.stageWidth * 0.9;
				seaTxt.x = _stage.stageWidth * 0.05;
				seaTxt.multiline = true;
				seaTxt.wordWrap = true;
				seaTxt.autoSize = "left";
				TextFieldUtils.setHtmlText(seaTxt,HtmlText.format(_data.seaTip,0xffffff));
				_seaTraffic.addChild(seaTxt);
			}
		}
		
		public function clear():void
		{
		}
	}
}